@extends('admin.app')

@section('breadcrumb')
    <div class="bg-light lter b-b wrapper-md">
        <ol class="breadcrumb bg-light lter m-n no-padder">
            <li><a href="{{ admin_action('HomeController@index') }}">主页</a></li>
            <li>网站管理</li>
            <li><a href="{{ admin_action('Web\FriendlyLinksController@index') }}">友情链接管理</a></li>
            <li class="active">修改友情链接</li>
        </ol>
    </div>
@endsection

@section('content')
    <div class="panel panel-default">
        <div class="panel-heading font-bold">
            友情链接表单
        </div>
        <div class="panel-body">
            <form enctype="multipart/form-data" class="form-horizontal form-validation"
                  action="{{ admin_action('Web\FriendlyLinksController@update',[$friendly_link]) }}" method="post">
                {{ csrf_field() }}
                {{ method_field('PUT') }}
                <div class="form-group">
                    <label class="col-lg-2 control-label">名称*</label>
                    <div class="col-lg-10">
                        <input type="text" class="form-control" name="name" value="{{ $friendly_link->name }}"
                               placeholder="请输入名称" data-rule-required="true" data-rule-maxlength="50">
                    </div>
                </div>

                <div class="line line-dashed b-b line-lg"></div>
                <div class="form-group">
                    <label class="col-lg-2 control-label">友情链接*</label>
                    <div class="col-lg-10">
                        <input type="text" class="form-control" name="link" value="{{ $friendly_link->link }}"
                               placeholder="请输入链接URl" data-rule-required="true" data-rule-maxlength="100">
                    </div>
                </div>
                <div class="line line-dashed b-b line-lg"></div>
                <div class="form-group">
                    <label class="col-lg-2 control-label">链接类型*</label>
                    <div class="col-lg-10">
                        <select class="form-control select2" name="link_type" data-rule-required="true">
                            <option value="">请选择链接类型</option>
                            @foreach($link_types as $link_type)
                                <option value="{{ $link_type->code }}" {{ $link_type->code==$friendly_link->link_type?'selected=selected':'' }}>{{ $link_type->name }}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="line line-dashed b-b line-lg"></div>
                <div class="form-group">
                    <label class="col-lg-2 control-label">链接图片*</label>
                    <div class="col-lg-10">
                        <input type="file" name="image" data-fileinput-image
                               data-image-url="{{ $friendly_link->image?asset($friendly_link->image):'' }}"/>
                    </div>
                </div>
                <div class="line line-dashed b-b line-lg"></div>
                <div class="form-group">
                    <label class="col-lg-2 control-label">排序*</label>
                    <div class="col-lg-10">
                        <input type="text" class="form-control" name="sort" value="{{ $friendly_link->sort??0 }}"
                               placeholder="请输入排序" data-rule-required="true" data-rule-digits="true">
                    </div>
                </div>
                <div class="line line-dashed b-b line-lg"></div>
                <div class="form-group">
                    <label class="col-lg-2 control-label">备注</label>
                    <div class="col-lg-10">
                        <textarea name="description" placeholder="请填写描述信息" class="form-control"
                                  data-rule-maxlength="100">{{ $friendly_link->description }}</textarea>
                    </div>
                </div>

                <div class="line line-dashed b-b line-lg"></div>
                <div class="form-group">
                    <div class="col-lg-4 col-lg-offset-2">
                        <a href="{{ admin_action('Web\FriendlyLinksController@index') }}" class="btn btn-default">返&nbsp;回</a>
                        <button type="submit" class="btn btn-primary">修&nbsp;改</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
@endsection
@section('scripts')
    <script>
        $('input[data-fileinput-image]').on('filecleared', function (event) {
            //成功移除了预览图片,添加null图片标识
            $('input[data-fileinput-image]').parent().parent().append('<input type="hidden" name="image" value="" />');
        });
    </script>
@endsection